package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.JoinTeamBean;
import com.qf.flash.http.response.PayResetResponse;
import com.qf.flash.http.response.TipsBean;
import com.qf.flash.model.PayParam;
import com.qf.flash.mvp.contract.PayParamContract;
import com.qf.flash.utils.LogUtil;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.Map;


/**
 * 获取支付参数
 * 2020/3/11 9:35
 */
public class PayParamPresenter extends BasePresenter<PayParamContract.View> implements PayParamContract.Presenter {


    @Override
    public void getStartTeamParam(Map<String, Object> map) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
        .START_TEAM(map)
                .compose(RxUtils.<PayParam>handleResult())
                .compose(RxUtils.<PayParam>io_main())
                .subscribeWith(new BaseSubscriber<PayParam>(mRootView) {
                    @Override
                    public void onSuccess(PayParam param) {
                        mRootView.getStParamSuccess(param);
                    }
                })
        );
    }

    @Override
    public void getJoinTeamParam(String orderId, int payType) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .JOIN_TEAM(uid, orderId, payType)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<JoinTeamBean>(mRootView) {
                    @Override
                    public void onSuccess(JoinTeamBean param) {
                        mRootView.getJoinParamSuccess(param);
                    }

                    @Override
                    public void onError(Throwable t) {
                        super.onError(t);
                        LogUtil.d(" getMessage: "+t.getMessage());
                    }


                })
        );
    }

    @Override
    public void getPayTips() {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .PAY_TIPS(uid)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<TipsBean>(mRootView) {
                    @Override
                    public void onSuccess(TipsBean param) {
                        mRootView.setOrderTips(param);
                    }
                })
        );
    }

    @Override
    public void payReset(String uid, String orderID, int payType) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .PAY_RESET_MONEY(uid, orderID, payType)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<PayResetResponse>(mRootView) {
                    @Override
                    public void onSuccess(PayResetResponse param) {
                        mRootView.payResetSuccess(param);
                    }

                    @Override
                    public void onError(Throwable t) {
                        super.onError(t);
                        LogUtil.d(" getMessage: "+t.getMessage());
                    }

                })
        );
    }
}
